package com.uidt.project.ptsj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.uidt.project.ptsj.domain.PlaceInfo;
import com.uidt.project.ptsj.obj.InspectionForPage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.project.ptsj.domain.Inspection;
import com.uidt.project.ptsj.service.IInspectionService;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.web.page.TableDataInfo;

/**
 * 巡检信息Controller
 * 
 * @author uidt
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/ptsj/inspection")
public class InspectionController extends BaseController
{
    @Autowired
    private IInspectionService ptsjInspectionService;

    /**
     * 查询巡检信息列表
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(Inspection ptsjInspection)
    {
        startPage();
        List<Inspection> list = ptsjInspectionService.selectInspectionList(ptsjInspection);
        return getDataTable(list);
    }

    /**
     * 导出巡检信息列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:inspection:export')")
    @Log(title = "巡检信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Inspection ptsjInspection)
    {
        List<Inspection> list = ptsjInspectionService.selectInspectionList(ptsjInspection);
        ExcelUtil<Inspection> util = new ExcelUtil<Inspection>(Inspection.class);
        util.exportExcel(response, list, "巡检信息数据");
    }

    /**
     * 获取巡检信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ptsjInspectionService.selectInspectionById(id));
    }

    /**
     * 新增巡检信息
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:inspection:add')")
//    @Log(title = "巡检信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionForPage inspection)
    {
//        return null;
        return toAjax(ptsjInspectionService.addInspection(inspection));
    }

    /**
     * 修改巡检信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:inspection:edit')")
    @Log(title = "巡检信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Inspection ptsjInspection)
    {
        return toAjax(ptsjInspectionService.updateInspection(ptsjInspection));
    }

    /**
     * 删除巡检信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:inspection:remove')")
    @Log(title = "巡检信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptsjInspectionService.deleteInspectionByIds(ids));
    }

    /**
     * 挂牌
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:place:add')")
    @Log(title = "场所信息", businessType = BusinessType.UPDATE)
    @PostMapping("/applycard")
    public AjaxResult applycard(@RequestBody Inspection ptsjInspection)
    {
        return toAjax(ptsjInspectionService.applyCard(ptsjInspection));
    }
}
